package appapi.service.impl;

import appapi.Request.EquiPageReq;
import appapi.dao.EquipReportMapper;
import appapi.dao.StaffMapper;
import appapi.entity.basic.UserInfo;
import appapi.entity.report.BringEquipEntity;
import appapi.entity.report.LeasedEquipEntity;
import appapi.entity.report.SelfEquipEntity;
import appapi.entity.report.SpecialEquipEntity;
import appapi.service.EquipReportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * 设备台账报表功能实现
 *
 * @author luocheng
 * @version 1.0
 * @date 2023/06/21 14:09
 */
@Service
public class EquipReportServiceImpl implements EquipReportService {
    @Autowired
    EquipReportMapper equipReportMapper;
    @Resource
    StaffMapper staffMapper;

    @Override
    public List<BringEquipEntity>  getBringEquipList(EquiPageReq req, UserInfo userInfo) {
        //未选择项目，则查询所有管辖项目
        if (req.getOrgaPathIds() == null) {
            //获取人员所属机构路径
            Map<String, Object> staffDto = staffMapper.selectStaffDetail(userInfo.getUserid());
            String orgaPathIds = staffDto.get("orgaPathIds").toString();
            req.setOrgaPathIds(orgaPathIds);
        }
        return equipReportMapper.queryBringEquipList(req);
    }

    @Override
    public List<LeasedEquipEntity> getLeasedEquipList(EquiPageReq req, UserInfo userInfo) {
        //未选择项目，则查询所有管辖项目
        if (req.getOrgaPathIds() == null) {
            //获取人员所属机构路径
            Map<String, Object> staffDto = staffMapper.selectStaffDetail(userInfo.getUserid());
            String orgaPathIds = staffDto.get("orgaPathIds").toString();
            req.setOrgaPathIds(orgaPathIds);
        }
        return equipReportMapper.queryLeasedEquipList(req);
    }

    @Override
    public List<SelfEquipEntity> getSelfEquipList(EquiPageReq req, UserInfo userInfo)
    {
        //未选择项目，则查询所有管辖项目
        if (req.getOrgaPathIds() == null) {
            //获取人员所属机构路径
            Map<String, Object> staffDto = staffMapper.selectStaffDetail(userInfo.getUserid());
            String orgaPathIds = staffDto.get("orgaPathIds").toString();
            req.setOrgaPathIds(orgaPathIds);
        }
        return equipReportMapper.querySelfEquipList(req);
    }

    @Override
    public List<SpecialEquipEntity> getSpecialEquipList(EquiPageReq req) {
        return equipReportMapper.querySpecialEquipList(req);
    }
}
